package com.woniuxy.enjoylife.controller;


import com.woniuxy.enjoylife.entity.Goods_order;
import com.woniuxy.enjoylife.entity.dto.ReturnGoodsOrderDto;
import com.woniuxy.enjoylife.entity.dto.SelectGoodsOrderDto;
import com.woniuxy.enjoylife.mapper.Goods_orderMapper;
import com.woniuxy.enjoylife.service.Goods_orderService;
import com.woniuxy.enjoylife.utils.OrderNumberCreator;
import com.woniuxy.enjoylife.utils.PageResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author teamEnjoyLife75
 * @since 2021-01-23
 */
@RestController
@RequestMapping("/goodsOrder")
public class Goods_orderController {
    @Resource
    private Goods_orderService goodsOrderService;
    @Resource
    private HttpServletRequest request;

    @RequestMapping("/insertGoodsOrder")
    public Boolean insertGoodsOrder(@RequestBody Goods_order goodsOrder){
        goodsOrder.setUid((int) request.getSession().getAttribute("id"));
        goodsOrder.setCreatetime(LocalDateTime.now());
        goodsOrder.setSerial(OrderNumberCreator.createGoodsOrderNum());
        return goodsOrderService.save(goodsOrder);
    }

    /**
     * 分页查询商品订单
     */
    @RequestMapping("/userSelectGoodsOrder")
    public PageResult<ReturnGoodsOrderDto> userSelectGoodsOrder(SelectGoodsOrderDto dto){
        dto.setUid((int) request.getSession().getAttribute("id"));
        return goodsOrderService.selectGoodsOrderDto(dto);
    }

    @RequestMapping("/selectGoodsOrder")
    public PageResult<ReturnGoodsOrderDto> selectGoodsOrder(SelectGoodsOrderDto dto){
        return goodsOrderService.selectGoodsOrderDto(dto);
    }

    @RequestMapping("/deleteOrder")
    public Boolean deleteOrder(int id){
        return goodsOrderService.deleteOrder(id);
    }

    @RequestMapping("/updateOrder")
    public Boolean updateOrder (@RequestBody Goods_order order){
        return goodsOrderService.updateOrder(order);
    }


}
